#-----------------------------------
# Name: Ethan Ryder
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 9/18/2013
# Version: 1.0.0
#----------------------------
import os

swearList = ["dumb",
             "stupid",
             "fuck",
             "shit",
             "jackass",
             "bullshit",
             "nigger",
             "chink",
             "cunt",
             "bastard",
             "dick",
             "penis",
             "whore",
             "nigga",
             "slut",
             "butt fuck",
             "fagget",
             "prostitute",
             "gay",
             "ass hole",
             "mo fo",
             "mother fucker",
             "hell",
             "bitch",
             "butt",
             "vagina",
             "dog shit"
             "rape",
             "fat",
             "69",
             "sex",
             "poo",
             "poop",
             "dumb",
             "stupid",
             "bad ass",
             "suck a left nut",
             "suck a right nut",
             "bite me",
             "douche",
             "douche bag",
             "retard"]
             
bgColor = '0'
txtColor = 'F'

def getMenuOption(maxOptions):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter a number or S or Q> ")
        option = option.upper()
        if option == 'S':
            goodOption = True
        elif option == 'Q' :
            goodOption = True
        elif option == "":
            pass
        else:
            isNum = True
            for character in option:
                if character not in "0123456789":
                    isNum = False
            if isNum:
                if int(option) <= 0:
                    isNum = False
                elif int(option) > maxOptions:
                    isNum = False
            if isNum:
                goodOption = True
            else:
                print "Please type a number!"
        if not goodOption:
            print "Invalid Choice, please try again. "
    return option

def menu():
    print "Welcome to Madlibs"
    print "Please Select an Option:"
    print " [1] The Attack of the Bananas"
    print " [2] My new vehicle"
    print " [3] water tubing"
    print " [S] Settings"
    print " [Q] Quit"
    option = getMenuOption(3)
    return option

def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearList:
            goodWord = True
        else:
            print "Naughty user...please be polite!"
        if not goodWord:
            print "Please try again."
    return word

def getNumber(prompt, min = "", max = ""):
        num = ""
        goodNumber = False
        while not goodNumber:
            num = raw_input(prompt)
            isNum = True
            for digit in num:
                if digit not in ".0123456789":
                    isNum = False
            if isNum:
                if min != "":
                    if float(num) < min:
                        isNum = False
                if max != "":
                    if float(num) > max:
                        isNum = False
            if isNum:
                goodNumber = True
            else:
                print "Please enter a valid number"
        return num
                    
def getColor(prompt):
    colors = ["black",
              "blue",
              "green",
              "bright white",
              "light red",
              'light yellow',
              'light green',
              "red",
              "purple"]
    opt = ""
    goodColor = False
    while not goodColor:
        opt = raw_input(prompt)
        if opt.lower() in colors:
            goodColor = True
    if opt == "black":
        color = '0'
    elif opt == 'blue':
        color = '1'
    elif opt == 'green':
        color = '2'
    elif opt == 'bright white':
        color = 'F'
    elif opt == 'light red':
        color = 'C'
    elif opt == 'red':
        color = '4'
    elif opt == 'purple':
        color = '5'
    elif opt == 'light yellow':
        color = 'E'
    elif opt == 'light green':
        color = 'A'
    return color
        
            
                    
def story1():
    place1 = getWord("Enter a place: ")
    game = getWord("Enter the name of a game: ")
    description1 = getWord("Enter a weather: ")
    roll = getNumber("enter a roll: ", 2 , 12)
    winOrLose = getWord("Enter Win or Lose: ")
    place2 = getWord("Enter place: ")
    place3 = getWord("Enter place: ")
    story += "It was "
    story += description1 + "day in "
    story += place1 + ". "
    story += "My friends and I were playing a game of "
    story += game + ", "
    story += "I rolled a "
    story += roll + ". "
    story += "it made me"
    story += winOrLose
    story += "I had to go to"
    story += place2 + ". "
    story += "but after I got out I bought the"
    story += place3 + ". "
    print
    print story
    print

def story2():
    vehicle = getWord("Enter a vehicle: ")
    relative = getWord("Enter a relative: ")
    building = getWord("Enter a building: ")
    condition = getWord("Enter a condition: ")
    action = getWord("Enter a action: ")
    action = getWord("Enter a action: ")
    place = getWord("Enter a place: ")
    story = "when I got my "
    story += vehicle + " "
    story += "I got home and my "
    story += relative + " opened my  "
    story += building + " and there it was. "
    story += "my very own " + vehicle + ". "
    story += "it was used but was in "
    story += condition + " condition."
    story += "so I got on it and started to"
    story += action + ". "
    story += "I went to the bottom of the drive way and"
    story += action + ". "
    story += "then I went back into the"
    story += place + ". "
    print story
    
def story3():
    sport = getWord("Enter a Sport: ")
    verb = getWord("Enter a verb: ")
    building = getWord("Enter a building: ")
    condition = getWord("Enter a condition: ")
    liquid = getWord("Enter a liquid: ")
    feeling = getWord("Enter a feeling: ")
    action = getWord("Enter a action: ")    
    story = "when I went"
    story += sport + " "
    story += "I could not "
    story += verb + " on  "
    story += "I had to let go"
    story += "I fell into the"
    story += liquid + ". "
    story += "when I let go it"
    story += feeling + ". "
    story += "then I started to"
    story += action + ". "
    print story


def settings():
    txtColor = getColor("Enter Text Color: ")
    bgColor = getColor("Enter Backgound Color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
    
def run():
    choice = ""
    while choice != 'Q':
        choice = menu()
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'S':
            settings()
        elif choice == 'Q':
            print " Goodbye"
            os.system("color " + bgColor + txtColor)
            raw_input("Press enter to exit")
        else:
            print "Something terrible has happened...go yell at the programmer"
    
run()
        
        
        
        
        
        
        